#include "docreader.h"
#include "ui_docreader.h"


docreader::docreader(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::docreader)
{
    ui->setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint);
    QFile file(RECORD_DOC);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return;
    ui->textBrowser->setText(trUtf8(file.readAll()));
    ui->print2usb_btn->hide();
    trackd=NULL;
}

void docreader::entrance()
{


}



docreader::~docreader()
{
    delete ui;
}

void docreader::on_open_file_btn_clicked()
{
    QString filter=ui->calendarWidget->selectedDate().toString("yyyyMMdd")+"*";
    filename = QFileDialog::getOpenFileName(this,
    trUtf8("打开文件"), RECORD_DIR ,filter);
    QCursor cursor(Qt::BlankCursor);
    QFile doc(filename);
     if (!doc.open(QIODevice::ReadOnly | QIODevice::Text)) return;
    ui->textBrowser->setText(trUtf8(doc.readAll()));

}


void docreader::on_print_clicked()
{
    BUTTON_SOUND
    if( Affirm("确认是否打印？"))
    {
        if(filename.isEmpty())  filename=RECORD_DOC;
        serialprinter->print_file(filename);
    }
}


void docreader::on_print2usb_btn_clicked()
{
    bool udisk_found=0;
    BUTTON_SOUND;

    if( Affirm("请插入U盘后按确定...\n数据传输过程中不要移除!"))
    {
     if(udisk_found)
     {
       system("mkdir -p /mnt/usb/history");
       system("cp -r /qt/sterilization/history /mnt/usb");
       system("umount /mnt/usb");
       WARN->show_text("打印成功！");
     }
     else  WARN->show_text("U盘未找到，打印失败！");
    }
}

void docreader::on_exit_btn_clicked()
{
     filename=RECORD_DOC;
}

void docreader::on_IO_tracker_clicked()
{
    QString filter=ui->calendarWidget->selectedDate().toString("yyyyMMdd")+"*";
    filename = QFileDialog::getOpenFileName(this,
    trUtf8("打开文件"), IODATA_RECORD_DIR ,filter);
    if(filename.isNull()) return;

    readfrom(filename,*track);

    if(NULL==trackd)  trackd=new tracker_display;
   // trackd->read_page(1);
    trackd->display_data();
    this->close();
    trackd->showFullScreen();


}
